################################################################################
#
# TIC-80
#
################################################################################

LIBRETRO_TIC80_VERSION = bd6ce86174fc7c9d7d3a86263acf3a7de1b62c11
LIBRETRO_TIC80_SITE = https://github.com/libretro/TIC-80.git
LIBRETRO_TIC80_LICENSE = MIT
LIBRETRO_TIC80_LICENSE_FILES = LICENSE
LIBRETRO_TIC80_SITE_METHOD=git
LIBRETRO_TIC80_GIT_SUBMODULES=y

LIBRETRO_TIC80_CONF_OPTS=-S $(@D)/core -DBUILD_SDL=OFF \
			-DBUILD_SOKOL=OFF \
			-DBUILD_LIBRETRO=ON \
			-DBUILD_DEMO_CARTS=OFF \
			-DBUILD_PLAYER=OFF \
			-DBUILD_PRO=TRUE

define LIBRETRO_TIC80_INSTALL_TARGET_CMDS
	mkdir -p "${BINARIES_DIR}/retroarch/cores"
	mkdir -p $(TARGET_DIR)/usr/lib/libretro
	$(INSTALL) -D $(@D)/lib/tic80_libretro.so \
		${BINARIES_DIR}/retroarch/cores/tic80_libretro.so
endef

LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_C_ARCHIVE_CREATE="<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>"
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_C_ARCHIVE_FINISH=true
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_CXX_ARCHIVE_CREATE="<CMAKE_AR> qcs <TARGET> <LINK_FLAGS> <OBJECTS>"
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_CXX_ARCHIVE_FINISH=true
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_AR="$(TARGET_CC)-ar"
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_C_COMPILER="$(TARGET_CC)"
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_CXX_COMPILER="$(TARGET_CXX)"
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_LINKER="$(TARGET_LD)"
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_C_FLAGS="$(COMPILER_COMMONS_CFLAGS_SO) -DDINGUX -Dd_m3LogOutput=0"
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_CXX_FLAGS="$(COMPILER_COMMONS_CXXFLAGS_SO)"
LIBRETRO_TIC80_CONF_OPTS += -DCMAKE_LINKER_EXE_FLAGS="$(COMPILER_COMMONS_LDFLAGS_SO)"
LIBRETRO_TIC80_CONF_OPTS +=  -DCMAKE_BUILD_TYPE=Release
$(eval $(cmake-package))
